<template>
  <div class="counter-container">
    <div class="counter-display">
      <span class="label">结果：</span>
      <span class="value">{{count }}</span>
      <!-- <span class="value">{{countStore.count }}</span> -->
      <span class="label"> doubled:</span>
      <span class="value">{{doubleCount }}</span>
    </div>
    <br>
    <!-- v-model.number:将输入的值转为数字类型 -->
    <div class="control-group">
      <select v-model.number="value" class="value-selector">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
      </select>
      <div class="button-group">
        <button @click="add()" class="btn btn-primary">加</button>
        <button @click="sub()" class="btn btn-secondary">减</button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: 'Count',
}
</script>

<script setup lang="ts">
import { ref } from 'vue'

import { useCountStore } from '@/store/Count'
import { storeToRefs } from 'pinia'
import { toRefs } from 'vue'
const value = ref<number>(1)
const countStore = useCountStore()
//修改数据的三种方法
const add = () => {
  // 第一种方法 小功能
  // useCountStore().count+=value.value;

  // // 第二种方法 批量修改数据
  // useCountStore().$patch({
  //   count: 888,
  //   address: "杭州"
  // });
  

  // 第三种 大型功能需要复用时可以使用
  countStore.increment(value.value)//调用increment方法并传参实现加减
}

const sub = () => {
  countStore.decrement(value.value)
}
//解构，区别两个响应式的不同
const { count, address,doubleCount,upperAddress } = storeToRefs(countStore);
console.log(toRefs(countStore));
console.log(storeToRefs(countStore));
</script>

<style scoped>
.counter-container {
  max-width: 400px;
  margin: 20px auto;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-family: 'Arial', sans-serif;
}

.counter-display {
  text-align: center;
  margin-bottom: 20px;
}

.label {
  font-size: 18px;
  font-weight: normal;
}

.value {
  font-size: 36px;
  font-weight: bold;
  margin-left: 10px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}

.value-selector {
  padding: 10px 15px;
  border-radius: 5px;
  border: none;
  background-color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.value-selector:hover {
  background-color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.button-group {
  display: flex;
  gap: 15px;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: #4CAF50;
  color: white;
}

.btn-primary:hover {
  background-color: #45a049;
}

.btn-secondary {
  background-color: #f44336;
  color: white;
}

.btn-secondary:hover {
  background-color: #d32f2f;
}

br {
  display: none;
}
</style>